/**
 * 
 */
package na.learn.java;


/**
 * 
 * @author nagrawal2
 */
public class SophieGermainPrimeRandonGenerator implements RandomNumberGenerator {

	private static int SeedInUse = 0;

	private static final long[] SophieGermainPrimes = { 3l, 5l, 11l, 23l, 29l,
			41l, 53l, 83l, 89l, 113l, 131l, 173l, 179l, 191l, 233l };

	private static final long[] SophieGermainS = new long[SophieGermainPrimes.length];

	static {
		int count = 0;
		for (long prime : SophieGermainPrimes)
			SophieGermainS[count++] = 2l * prime + 1l;

	}

	public int getRandomNumber(Object obj) {
		//System.out.println(obj.hashCode());
		double inverse = 1.0d / SophieGermainS[(++SeedInUse) % SophieGermainS.length];
		long numberOne = new Double((obj.hashCode() * inverse) * 10000)
				.longValue();
		long numberTwo = new Double((obj.hashCode() * inverse) * 1000)
				.longValue();
		return new Long(numberOne - numberTwo).intValue();

	}
	
	
	
	public static void main(String[] args){
		System.out.println("Num: "  + new SophieGermainPrimeRandonGenerator().getRandomNumber(new String("CD")));
	}
}
